package x.ovo.wechat.bot.core.message;

import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 撤回的消息
 *
 * @author ovo, created by 2024/07/06
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class RevokeMessage extends Message {

    private static final Pattern PATTERN = Pattern.compile(";msgid&gt;(\\d+)&lt;/");
    private static final Pattern PATTERN_PLACEHOLDER = Pattern.compile("&lt;replacemsg&gt;&lt;!\\[CDATA\\[(.*)]]&gt;&lt;/replacemsg&gt;");

    private String placeholder;

    @Override
    public String getContent() {
        Matcher matcher = PATTERN_PLACEHOLDER.matcher(super.content);
        if (matcher.find()) return matcher.group(1);
        return null;
    }

    /**
     * 获取已撤销消息 ID
     *
     * @return {@link String}
     */
    public String getRevokedMessageId() {
        Matcher matcher = PATTERN.matcher(super.content);
        if (matcher.find()) return matcher.group(1);
        return null;
    }
}
